#ifndef GAUSSIAN_NOISE_H
#define GAUSSIAN_NOISE_H
#include <cmath>
//#include <limits>
//#include <cstdlib>
//#include <iostream>
#define TWO_PI 2.0*3.14159265358979323846
//using namespace cv;
using namespace std;
//生成高斯噪声
static double generateGaussianNoise() {

  static bool hasSpare = false;

  static double rand1, rand2;



  if (hasSpare) {

    hasSpare = false;

    return sqrt(rand1) * sin(rand2);

  }



  hasSpare = true;

  rand1 = rand() / ((double) RAND_MAX);

  if (rand1 < 1e-100){

    rand1 = 1e-100;

  }

  rand1 = -2 * log(rand1);

  rand2 = (rand() / ((double)RAND_MAX))*TWO_PI;



  return sqrt(rand1) * cos(rand2);

}




#endif // GAUSSIAN_NOISE_H
